package org.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.qf.service.SmbmsBillService;
import org.qf.service.SmbmsProviderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.qf.dao.SmbmsbillDao;
import org.qf.entity.SmbmsBill;
import org.qf.entity.SmbmsProvider;

import java.util.List;

@Slf4j
@Service
public class SmbmsBillServicelmpl implements SmbmsBillService {
    @Autowired
    SmbmsbillDao smbmsbillDao;

    /**
     * 查询账单
     *
     * @param smbmsBill
     * @return
     */
    @Override
    public PageInfo<SmbmsBill> showBillList(int currPage, SmbmsBill smbmsBill) {
        PageHelper.startPage(currPage, 5);
        List<SmbmsBill> list = smbmsbillDao.showBillList(smbmsBill);
        PageInfo<SmbmsBill> pageInfo = new PageInfo<>(list);
        if (pageInfo.getList().size() > 0) {
            return pageInfo;
        } else {
            return null;
        }
    }

    /**
     * 添加账单
     *
     * @param smbmsBill
     * @return
     */
    @Override
    public int addBill(SmbmsBill smbmsBill) {
        int i = smbmsbillDao.addBill(smbmsBill);
        if (i > 0) {
            return i;
        } else {
            return 0;
        }
    }

    /**
     * 列出供应商
     *
     * @return
     */
    @Override
    public List<SmbmsProvider> ListProvider() {
        List<SmbmsProvider> provides = smbmsbillDao.ListProvider();
        if (provides.size() > 0) {
            return provides;
        } else {
            return null;
        }
    }

    /**
     * 通过id查找账单信息
     *
     * @param id
     * @return
     */
    @Override
    public SmbmsBill showBillById(int id) {
        return smbmsbillDao.showBillById(id);
    }

    /**
     * 修改账单
     * @param smbmsBill
     * @return
     */
    @Override
    public int updateBill(SmbmsBill smbmsBill) {
        return smbmsbillDao.updateBill(smbmsBill);
    }

    /**
     * 删除账单
     * @param id
     * @return
     */
    @Override
    public int deleteBill(int id) {
        return smbmsbillDao.deleteBill(id);
    }
}
